package com.demo.test;

import com.demo.pojo.LogisticsVo;
import com.taobao.pac.sdk.cp.PacClient;
import com.taobao.pac.sdk.cp.SendSysParams;
import com.taobao.pac.sdk.cp.dataobject.request.TRACK_DETAIL_INFO_CALLBACK.TrackDetailInfoCallbackRequest;
import com.taobao.pac.sdk.cp.dataobject.response.TRACK_DETAIL_INFO_CALLBACK.TrackDetailInfoCallbackResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 查询物流轨迹详情
 */
@Slf4j
@RestController
@RequestMapping("logisticsStaus")
public class CaiNiaoTest3 {

    //菜鸟物流云地址
    public static final String httpUrl = "https://link.cainiao.com/gateway/link.do";

    public static final String appKey  = "277864";

    public static final String appSecret  = "j86Id82HKa38s9O347g05y00T2Zmp1O9";

    public static final String fromCode  = "8f716c65";

    @GetMapping("followLogistics")
    public static void logisticsStaus(@RequestBody LogisticsVo logisticsVo){

        //联调时指定预发环境, 注意正式上线后请替换正式地址。
        PacClient pacClient = new PacClient(appKey, appSecret, httpUrl);

        SendSysParams sendSysParams = new SendSysParams();
        sendSysParams.setToCode("TRACK"); //具体值看对应接口文档说明
        sendSysParams.setFromCode(fromCode);//一定要填写自己的cpcode , ISV请求填写token值

        TrackDetailInfoCallbackRequest request = new TrackDetailInfoCallbackRequest();

        request.setMailNo("LP00493205170481");
        request.setShowStandard(true);

        TrackDetailInfoCallbackResponse response = pacClient.send(request, sendSysParams);

        System.out.println(response);
    }

}
